package com.mediacloud.app.newsmodule.fragment.baoliao.holder;

import android.content.Context;
import android.graphics.drawable.Drawable;

import androidx.recyclerview.widget.RecyclerView;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mediacloud.app.assembly.util.FunKt;
import com.mediacloud.app.model.FacadeBean;
import com.mediacloud.app.model.utils.DefaultBgUtil;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.fragment.baoliao.XPlayerVideoListPlayerUtil;
import com.mediacloud.app.newsmodule.fragment.baoliao.adapter.BaoLiaoNavListAdapter;
import com.mediacloud.app.newsmodule.model.baoliao.list.list.BaoNiaoListItem;
import com.mediacloud.app.newsmodule.utils.FacadeInvoker;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;
import com.zimeiti.view.CollapsedTextViewAppfac;

public class BaoLiaoNavListPureTxtHolder extends RecyclerView.ViewHolder implements BaoLiaoNavListAdapter.IBaoLiaoListHolder, CollapsedTextViewAppfac.ShowHideAllListener {
    ImageView baoniaoRenNaoKe;
    TextView baoniaoren;
    TextView baoniaoshijian;
    public CollapsedTextViewAppfac baoniaobiaoti;
    TextView baoniaodianzanshu, baoniaodianpinglunshu;
    protected Drawable defaultLoading;
    protected TextView baoniaoTitle;
    protected TextView baoniaoCategroy;
    protected View lanmu_line;
    public View moreIcon, moreIcon2;
    public TextView rankTv;
    public XPlayerVideoListPlayerUtil videoListPlayerUtil;
    public TextView baoLiaoCommentNum;
    private Context context;

    public BaoLiaoNavListPureTxtHolder(View itemView) {
        super(itemView);
        defaultLoading = AppFactoryGlobalConfig.getDefaultImageLoadDrawable();
        rankTv = itemView.findViewById(R.id.text_rank);
        baoLiaoCommentNum = itemView.findViewById(R.id.baoLiaoCommentNum);
        baoniaoRenNaoKe = itemView.findViewById(R.id.baoniaoRenNaoKe);
        baoniaoTitle = itemView.findViewById(R.id.baoniaoTitle);
        baoniaoCategroy = itemView.findViewById(R.id.tv_bao_liao_lan_mu);
        lanmu_line = itemView.findViewById(R.id.lanmu_line);
        baoniaoren = itemView.findViewById(R.id.baoniaoren);
        baoniaoshijian = itemView.findViewById(R.id.baoniaoshijian);
        baoniaobiaoti = itemView.findViewById(R.id.baoniaobiaoti);
        baoniaodianzanshu = itemView.findViewById(R.id.baoniaodianzanshu);
        baoniaodianpinglunshu = itemView.findViewById(R.id.baoniaodianpinglunshu);

        moreIcon = itemView.findViewById(R.id.moreIcon);
        moreIcon2 = itemView.findViewById(R.id.moreIcon2);
        this.context = itemView.getContext();
        if (baoniaobiaoti != null)
            baoniaobiaoti.setTipsColor(DefaultBgUtil.getTintColor(itemView.getContext()));
    }

    public void setVideoListPlayerUtil(XPlayerVideoListPlayerUtil baoLiaoVideoListPlayerUtil) {
        this.videoListPlayerUtil = baoLiaoVideoListPlayerUtil;
    }

    @Override
    public void updateData(BaoNiaoListItem item,int position) {
//        GlideUtils.loadUrl(item.getAvatar(),baoniaoRenNaoKe,null, defaultLoading);
        //  baoniaoren.setTextColor(DefaultBgUtil.getTintColor(itemView.getContext()));
        baoniaobiaoti.showHideAllListener = this;
       // GlideUtils.loadUrl(item.getAvatar(), baoniaoRenNaoKe, null, defaultLoading, false, true);
        FunKt.loadRound(baoniaoRenNaoKe,item.getAvatar(),defaultLoading,null);
        baoniaoren.setText(item.getNickName());
        baoniaoshijian.setText((TextUtils.isEmpty(item.getPublishTime())?item.getAddTime():item.getPublishTime()));
        baoniaobiaoti.mShowWidth = 0;
        baoniaobiaoti.mIsExpanded = item.showAll;
        baoniaobiaoti.setText(item.getContent());
        baoniaobiaoti.setTipsColor(DefaultBgUtil.getTintColor(itemView.getContext()));
        if(TextUtils.isEmpty(item.getContent())){
            baoniaobiaoti.setVisibility(View.GONE);
        }else{
            baoniaobiaoti.setVisibility(View.VISIBLE);
        }
  /*      reflect.set("mIsExpanded", false);
        reflect.set("mShowWidth", 0);*/
        if (TextUtils.isEmpty(item.getTitle())) {
            baoniaoTitle.setText("");
        } else {
            baoniaoTitle.setText(item.getTitle());
        }
        if (TextUtils.isEmpty(item.getCatalogName())) {
            baoniaoCategroy.setVisibility(View.GONE);
            if (lanmu_line != null) {
                lanmu_line.setVisibility(View.GONE);
            }
        } else {
            baoniaoCategroy.setText(item.getCatalogName());
            //     baoniaoCategroy.setTextColor(DefaultBgUtil.getTintColor(itemView.getContext()));
            baoniaoCategroy.setVisibility(View.VISIBLE);
            if (lanmu_line != null) {
                lanmu_line.setVisibility(View.VISIBLE);
            }
        }
        baoniaodianzanshu.setText(String.valueOf(item.getFavorCount()));
        baoniaodianpinglunshu.setText(String.valueOf(item.getHitcount()));
        baoLiaoCommentNum.setText(String.valueOf(item.getCommentCount()));
    }

    @Override
    public void appfacShowHide(boolean showAll) {
        BaoNiaoListItem baoNiaoListItem = itemView.getTag(R.id.tagSaveId) != null ? (BaoNiaoListItem) itemView.getTag(R.id.tagSaveId) : null;
        if (baoNiaoListItem != null) {
            baoNiaoListItem.showAll = showAll;
        }
    }
}